// ==UserScript==
// @name         Mikanani 批量复制SSR订阅地址
// @namespace    http://tampermonkey.net/
// @version      1.0.5
// @description  批量复制当前页面番剧的SSR订阅地址
// @author       小莫
// @match        https://mikanani.me
// @icon         
// @grant        none
// ==/UserScript==

(function () {
    'use strict';

    // 添加按钮
    let button = document.createElement("button");
    button.innerHTML = "复制RSS";
    button.style = "position: fixed; top: 0; right: 0; z-index: 9999;";
    button.onclick = copyRSSList;
    document.body.appendChild(button);


    function copyRSSList() {
        let list = []
        let fadeIn = document.getElementsByClassName("fadeIn");
        for (let i = 0; i < fadeIn.length; i++) {
            const element = fadeIn[i];
            let expand_bangumi = element.getElementsByClassName("js-expand_bangumi")
            for (let o = 0; o < expand_bangumi.length; o++) {
                const item = expand_bangumi[o];
                let bangumiid = item.getAttribute("data-bangumiid");
                let data_src = item.getAttribute("data-src");
                let logo = item.getAttribute("style");
                let img = ''
                if (data_src) {
                    img = data_src
                } else {
                    img = logo.match(/url\(\"(.*?)\"\)/)[1];
                }
                // img = /images/Bangumi/202404/74274e3b.jpg?width=400&height=400&format=webp
                img = img.split('?')[0];
                list.push({
                    "RSS": [
                        `https://mikanani.me/RSS/Bangumi?bangumiId=${bangumiid}&subgroupid=552`,
                        `https://mikanani.me/RSS/Bangumi?bangumiId=${bangumiid}&subgroupid=370`,
                        `https://mikanani.me/RSS/Bangumi?bangumiId=${bangumiid}&subgroupid=583`,
                    ],
                    "logo": `https://mikanani.me${img}?format=webp`,
                    "bangumiId": bangumiid
                })
            }
        }
        console.log(list);
    }
})();